package ams.model.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.struts2.json.annotations.JSON;

@Entity
@Table(name = "t_rights")
public class Rights {

	// 权限id
	private Integer id;
	// 父权限id
	private Integer pid;
	// 权限编码
	private String code;
	// 权限名称
	private String name;
	// 权限类型
	private String type;
	// 权限图标
	private String icon;
	// 权限url
	private String url;
	// 是否为叶子节点，在treegrid中state=open为叶子节点
	private String state;

	private Set<RoleRights> roleRights = new HashSet<>();
	
	public Rights() {

	}

	public Rights(Integer id, Integer pid, String code, String name, String type, String icon, String url,
			String state) {
		super();
		this.id = id;
		this.pid = pid;
		this.code = code;
		this.name = name;
		this.type = type;
		this.icon = icon;
		this.url = url;
		this.state = state;
	}
	
	public Rights(Integer id, Integer pid, String name) {
		super();
		this.id = id;
		this.pid = pid;
		this.name = name;
	}

	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "pid")
	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	@Column(name = "code", nullable = false)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "name", nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "type", nullable = false)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "icon")
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Column(name = "url")
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "state")
	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	@JSON(serialize = false)
	@OneToMany(mappedBy = "rights", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	public Set<RoleRights> getRoleRights() {
		return roleRights;
	}

	public void setRoleRights(Set<RoleRights> roleRights) {
		this.roleRights = roleRights;
	}


	@Override
	public String toString() {
		return "Rights [id=" + id + ", pid=" + pid + ", code=" + code + ", name=" + name + ", type=" + type + ", icon="
				+ icon + ", url=" + url + ", state=" + state + "]";
	}

}
